package controller

import (
	"github.com/gofiber/fiber"
	"gowork/productionInformation/model"
	"strconv"
)

type ProductionInformationController struct {
	ProductionInformation *model.ProductionInformation
}

func (pic *ProductionInformationController)InsertProductionInformation(c *fiber.Ctx){

	pic.ProductionInformation = new(model.ProductionInformation)

	var productionInformation model.ProductionInformation
	c.BodyParser(&productionInformation)

	res , err := pic.ProductionInformation.InsertProductionInformation(&productionInformation)
	if err != nil{
		c.JSON(fiber.Map{
			"code": 500,
			"data": nil,
			"message": err.Error(),
		})
		return
	}

	c.JSON(fiber.Map{
		"code": res["code"],
		"data": nil,
		"message": res["message"],
	})
	return
}

func (pic *ProductionInformationController)QueryProductionInformation(c *fiber.Ctx){

	pic.ProductionInformation = new(model.ProductionInformation)

	productionInformationIdStr := c.FormValue("productionInformationId")
	productionInformationId, err := strconv.ParseInt(productionInformationIdStr,10, 64)
	if err != nil{
		c.JSON(fiber.Map{
			"code": 500,
			"data": nil,
			"message": err.Error(),
		})
		return
	}

	res , err := pic.ProductionInformation.QueryProductionInformation(productionInformationId)
	if err != nil{
		c.JSON(fiber.Map{
			"code": 500,
			"data": nil,
			"message": err.Error(),
		})
		return
	}

	c.JSON(fiber.Map{
		"code": "200",
		"data": res,
		"message": "成功",
	})
	return
}
